SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for tms_customer_follow_up
-- ----------------------------
DROP TABLE IF EXISTS `tms_customer_follow_up`;
CREATE TABLE `tms_customer_follow_up` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
  `company_id` bigint NOT NULL COMMENT '公司ID',
  `company_name` varchar(255) NOT NULL COMMENT '公司名字',
  `company_address` varchar(500) DEFAULT NULL COMMENT '公司地址',
  `company_mode` varchar(50) DEFAULT NULL COMMENT '公司模式（字典：company_mode）',
  `principal` varchar(100) DEFAULT NULL COMMENT '负责人',
  `visitor` varchar(100) DEFAULT NULL COMMENT '访问人员',
  `visit_time` datetime DEFAULT NULL COMMENT '走访时间',
  `personal_preference` varchar(500) DEFAULT NULL COMMENT '个人喜好',
  `business_volume` varchar(200) DEFAULT NULL COMMENT '业务量',
  `training_situation` varchar(500) DEFAULT NULL COMMENT '培训情况',
  `partner` varchar(255) DEFAULT NULL COMMENT '对方合作商',
  `follow_status` varchar(50) DEFAULT NULL COMMENT '跟进状态（字典：follow_status）',
  `next_follow_time` datetime DEFAULT NULL COMMENT '下次跟进时间',
  `remark` text COMMENT '备注',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bigint NOT NULL DEFAULT 0 COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_company_id` (`company_id`) USING BTREE,
  KEY `idx_follow_status` (`follow_status`) USING BTREE,
  KEY `idx_next_follow_time` (`next_follow_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='客户跟进表';

-- ----------------------------
-- Table structure for tms_customer_follow_log
-- ----------------------------
DROP TABLE IF EXISTS `tms_customer_follow_log`;
CREATE TABLE `tms_customer_follow_log` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
  `follow_up_id` bigint NOT NULL COMMENT '跟进记录ID',
  `company_id` bigint NOT NULL COMMENT '公司ID',
  `follow_type` varchar(50) DEFAULT NULL COMMENT '跟进类型（字典：follow_type）',
  `follow_content` text COMMENT '跟进内容',
  `follow_result` varchar(500) DEFAULT NULL COMMENT '跟进结果',
  `next_plan` varchar(500) DEFAULT NULL COMMENT '下一步计划',
  `attachments` text COMMENT '附件（JSON数组）',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bigint NOT NULL DEFAULT 0 COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_follow_up_id` (`follow_up_id`) USING BTREE,
  KEY `idx_company_id` (`company_id`) USING BTREE,
  KEY `idx_create_time` (`create_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='客户跟进日志';

-- ----------------------------
-- Records
-- ----------------------------
BEGIN;
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;


-- 菜单 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
           '客户跟进管理', '', 2, 0, 5042,
           'customer-follow-up', '', 'tms/customerfollowup/index', 0, 'CustomerFollowUp'
       );

-- 按钮父菜单ID
-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话，需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();

-- 按钮 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进查询', 'tms:customer-follow-up:query', 3, 1, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进创建', 'tms:customer-follow-up:create', 3, 2, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进更新', 'tms:customer-follow-up:update', 3, 3, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进删除', 'tms:customer-follow-up:delete', 3, 4, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进导出', 'tms:customer-follow-up:export', 3, 5, @parentId,
           '', '', '', 0
       );

-- 菜单 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
           '客户跟进日志管理', '', 2, 0, 5042,
           'customer-follow-log', '', 'tms/customerfollowlog/index', 0, 'CustomerFollowLog'
       );

-- 按钮父菜单ID
-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话，需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();

-- 按钮 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进日志查询', 'tms:customer-follow-log:query', 3, 1, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进日志创建', 'tms:customer-follow-log:create', 3, 2, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进日志更新', 'tms:customer-follow-log:update', 3, 3, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进日志删除', 'tms:customer-follow-log:delete', 3, 4, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户跟进日志导出', 'tms:customer-follow-log:export', 3, 5, @parentId,
           '', '', '', 0
       );


-- 菜单 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status, component_name
)
VALUES (
           '客户背调管理', '', 2, 0, 5042,
           'customer-background', '', 'tms/customerbackground/index', 0, 'CustomerBackground'
       );

-- 按钮父菜单ID
-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话，需要手动修改 @parentId 的部分的代码
SELECT @parentId := LAST_INSERT_ID();

-- 按钮 SQL
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户背调查询', 'tms:customer-background:query', 3, 1, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户背调创建', 'tms:customer-background:create', 3, 2, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户背调更新', 'tms:customer-background:update', 3, 3, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户背调删除', 'tms:customer-background:delete', 3, 4, @parentId,
           '', '', '', 0
       );
INSERT INTO system_menu(
    name, permission, type, sort, parent_id,
    path, icon, component, status
)
VALUES (
           '客户背调导出', 'tms:customer-background:export', 3, 5, @parentId,
           '', '', '', 0
       );